/**
 * ======================================
 * 辖区管理
 * author: SKY-D
 * file: index.vue
 * date: 2022/6/12 14:50
 * ======================================
 */
<template>
  <page>
    <!--    查询条件-->
    <el-row slot="where">
      <el-col :span="24" class="k-text-left k-lh-2-2">
        <el-button class="k-mr-10" @click="handleCreate">新增</el-button>
        <el-input v-model="WHERE.search" class="k-width-150-p k-mr-10" placeholder="管理人/地区：" />
        <address-select v-model="WHERE.address" class="k-mr-10" />
        <el-button type="primary" @click="_search">查询</el-button>
        <el-button type="info" @click="_reset">重置</el-button>
      </el-col>
    </el-row>
    <!--    表格-->
    <el-table
      slot="table"
      ref="tb"
      v-loading="LOADING"
      :data="CLASS_TABLE_DATA"
      :size="SIZE"
      border
      :height="LIST_HEIGHT"
      style="width: 100%"
      @selection-change="_handleSelectionChange"
    >
      <el-table-column
        type="selection"
        width="55"
      />
      <template v-for="(item) in setting">
        <el-table-column
          v-if="item.key === 'action'"
          :key="item.id"
          :label="item.name"
          :prop="item.key"
          :width="item.value"
        >
          <template slot-scope="scope">
            <el-button v-permission="['REGION:EDIT']" @click="handleEdit(scope.row)">编辑</el-button>
            <el-button v-permission="['REGION:DEL']" @click="handleDel(scope.row)">删除</el-button>
          </template>
        </el-table-column>
        <el-table-column
          v-else
          :key="item.id"
          :label="item.name"
          :prop="item.key"
          :width="item.value"
        />
      </template>
    </el-table>
    <!--    分页-->
    <pagination slot="pagination" />
    <!--    弹窗-->
    <template slot="modal">
      <form-modal :visible.sync="FORM_VISIBLE" :type="FORM_TYPE" :data="FORM_DATA" @refresh="_getList" />
    </template>
  </page>
</template>

<script>
import list from '@/list'
import JurisdictionClass from '@/models/jurisdiction-class'
import { del, getList } from '@/api/jurisdiction'
import formModal from './components/form'
const jurisdictionClass = new JurisdictionClass()
import AddressSelect from '@/components/Select/addressSelect'
export default {
  name: 'DeepInterpretationOrder',
  components: { formModal, AddressSelect },
  mixins: [list],
  data() {
    return {
      caseRequestURLType: '',
      setting: jurisdictionClass.list(),
      WHERE: {
        search: '', // 访问类型
        address: {
          area: '',
          city: '',
          province: '',
          street: ''
        } // 访问类型
      }
    }
  },
  created() {
    this.LIST_API = getList
    // 调试===============
    // this.$store.commit('user/SET_PERMISSION', ['jurisdiction:list'])
    // 调试---------------
  },
  mounted() {
  },
  methods: {
    _setClass() {
      console.log('[mixin][list]设置类')
      const list = []
      this.TABLE_DATA.forEach(v => {
        const item = new JurisdictionClass(v)
        list.push(item)
      })
      this.CLASS_TABLE_DATA = list
    },
    handleCreate() {
      console.log('新增')
      this.FORM_TYPE = 'create'
      this.FORM_VISIBLE = true
    },
    handleEdit(item) {
      console.log('编辑', item)
      this.FORM_TYPE = 'edit'
      this.FORM_DATA = item
      this.FORM_VISIBLE = true
    },
    handleDel(item) {
      console.log('删除', item)
      this.$confirm('确认删除？')
        .then(_ => {
          del(item.id).then(res => {
            console.log('删除结果', res)
            this._showSuccess('删除成功')
            this._getList()
          })
        })
        .catch(_ => {})
    }
  }
}
</script>
